<template>
  <el-header class="user-header">
    <div class="header-content">
      <div class="path-nav">
        <el-icon v-if="currentPath.length && !isPreviewing" class="back-icon" @click="goBack">
          <ArrowLeft />
        </el-icon>
        <h1></h1>
      </div>
      <el-dropdown @command="handleCommand" trigger="click">
        <div class="user-info">
          <el-icon class="user-icon">
            <User />
          </el-icon>
          <span class="username">{{ username }}</span>
        </div>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item command="updatePassword">修改密码</el-dropdown-item>
            <el-dropdown-item command="logout">退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </el-header>
</template>

<script>
import { ArrowLeft, User } from '@element-plus/icons-vue'

export default {
  components: { ArrowLeft, User },
  props: {
    username: String,
    currentPath: Array,
    isPreviewing: Boolean
  },
  methods: {
    handleCommand(command) {
      this.$emit(command === 'logout' ? 'logout' : 'update-password')
    },
    goBack() {
      this.$emit('go-back')
    }
  }
}
</script>

<style scoped>
.user-header {
  background-color: #f0f2f5;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6rem;
}

.user-info {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.user-icon {
  font-size: 3rem;
  margin-right: 8px;
}

.username {
  font-size: 2rem;
}
</style>
